﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    ViewFWUser currentUserInfo = base.Context.Session.GetUserInfo();
}

@if (!currentUserInfo.IsHaveRights("Demo_Student2", "00"))
{
    throw new Exception(@L("您没有该页面的权限"));
}

@section styles{
    <link href="~/lib/YdmJUI/static/plugins/ueditorAPP/xiumi-ue-v5.css" rel="stylesheet" />
}
@section scripts{
    @*<script src="~/js/views/Main/Home/index.js" asp-append-version="true"></script>*@
    <script src="~/lib/YdmJUI/static/plugins/ueditorAPP/ueditor.config.js"></script>
    <script src="~/lib/YdmJUI/static/plugins/ueditorAPP/ueditor.all.min.js"></script>
    <script src="~/lib/YdmJUI/static/plugins/ueditorAPP/xiumi-ue-dialog-v5.js"></script>
}

<div data-toggle="topjui-layout" data-options="fit:true">
    @*<div data-options="region:'north',title:'<span style=\'margin-right:6px\'>@L("查找")</span> <button class=\'layui-btn layui-btn-xs\' onclick=\'saveSearchForm()\'>保存查询</button><button class=\'layui-btn layui-btn-xs\' onclick=\'loadSeachForm()\'>加载查询</button>',split:true" style="height:170px;padding-left:10px">
        <form id="mySearchForm" style="display:none">
            <table style="width:100%;border-collapse:separate; border-spacing:0px 10px;">
                <tr>
                    <td class="label">@L("学生性别")</td>
                    <td>
                        <input id="mySearchFormIsMan" type="text" name="isVIP"
                               data-toggle="topjui-combobox"
                               data-options="width:250,data:[{value:'',text:''},{value:'@L("是")',text:'@L("是")'},{value:'@L("否")',text:'@L("否")'}]" data-name="isMan" data-op="eq" data-datatype="tinyint">
                    </td>
                </tr>
            </table>
            <div style="position:absolute;right:20px; bottom:10px;">
              <a href="#" data-toggle="topjui-linkbutton" data-options="iconCls:'fa fa-search-minus', btnCls:'topjui-btn-search'" onclick="searchQuery()">@L("搜索(enter)")</a>
                <a href="#" data-toggle="topjui-linkbutton" data-options="iconCls:'fa fa-mail-reply', btnCls:'topjui-btn-clear'" onclick="$('#mySearchForm').form('clear')">@L("清空(esc)")</a>
            </div>
        </form>
    </div>*@

    <div data-options="region:'center',title:'',fit:false,split:true,border:false">
        <table id="myDg"></table>

        <div id="myDg-toolbar" class="topjui-toolbar" style="height:72px;display:block" data-options="
        grid:{
            type:'datagrid',
            id:'myDg'
            }"> 
            <!--如果要需要在列头加查询那么需要加上 style="height:72px;display:block" 样式 -->

            @if (currentUserInfo.IsHaveRights("Demo_Student2", "01") && base.Context.Request.Query["mode"]!="3")
            {
                <a id="add" href="javascript:void(0)" data-toggle="topjui-menubutton"
                    data-options="iconCls:'fa fa-plus',onClick: oepnAddDiag">
                    @L("新增")
                </a>
            }

           @* @if (currentUserInfo.IsHaveRights("Demo_Student2", "91") && base.Context.Request.Query["mode"]!="3")
            {
                    <a href="javascript:void(0)"
                    data-toggle="topjui-menubutton"
                    data-options="
                    method:'import',
                    extend: '#myDg-toolbar',
                    iconCls:'fa fa-cloud-upload',
                    btnCls:'topjui-btn-blue',
                    exportTemplateUrl:'/api/services/app/File/DownFile?type=Demo_Student2',
                    uploadUrl:'/api/services/app/File/UploadFileNew?type=Demo_Student2',
                    tableName:'Demo_Student2',
                    url:'/api/services/app/DemoStudent2/ImportExcel'">@L("导入")
                   </a>
            }*@

            @if (currentUserInfo.IsHaveRights("Demo_Student2", "03") && base.Context.Request.Query["mode"]!="3")
            {
                    <a href="javascript:void(0)" data-toggle="topjui-menubutton" data-options="
                    method:'doAjax',
                    btnCls:'topjui-btn-delete',
                    extend: '#myDg-toolbar',
                    iconCls:'fa fa-trash',
                    validateFun:vaildateBatchDelete,
                    confirmMsg:'@L("确定删除选中的数据吗")?',
                    grid: {uncheckedMsg:'@L("请勾选要删除的数据")',param:'id:id'},
                    url:'/api/services/app/DemoStudent2/BatchDelete' ">@L("删除")
                    </a>
            }

            <a href="javascript:void(0)"
                data-toggle="topjui-menubutton"
                data-options="
                method:'filter',
                extend: '#myDg-toolbar',
                btnCls:'topjui-btn-filter'">@L("过滤")
            </a>

            <a href="javascript:void(0)"
                   data-toggle="topjui-menubutton"
                   data-options="
                   method:'search',
                   extend: '#myDg-toolbar' ,
                   btnCls:'topjui-btn-query'">@L("查询")
            </a>

            @if (currentUserInfo.IsHaveRights("Demo_Student2", "92"))
            {
                <a href="javascript:void(0)"
                    data-toggle="topjui-menubutton"
                    data-options="
                    method:'export',
                    extend: '#myDg-toolbar',
                    iconCls:'fa fa-cloud-download',
                    btnCls:'topjui-btn-export',
                    excelExportName:'学生表',
                    url:'/api/services/app/DemoStudent2/GetGridExcel'">@L("导出")
               </a>
            }

            @if (currentUserInfo.IsHaveRights("Demo_Student2", "02") && base.Context.Request.Query["mode"]!="3")
            {
                <a href="javascript:void(0)"
                    data-toggle="topjui-menubutton"
                   data-options="iconCls:'fa fa-pencil',btnCls:'topjui-btn-blue',onClick:batchUpdate">@L("批量更新")
                </a>
            }

            @*<a href="javascript:void(0)"
                data-toggle="topjui-menubutton"
                data-options="
                    btnCls:'topjui-btn-black',
                    onClick:demoStudent2Index.selfClick">@L("自定义方法")
            </a>*@

            <!--汇总数据-->
            @*<span id="spnGridSummary" class="spn-grid-summary">
            </span>*@
            
            <!--添加queryForm-->
             <hr style="margin: 3px 0">
             <form id="myQueryForm" class="search-box" style="float:left">
                 <span>
                     <label>@L("学生性别")</label>
                     <input id="myQueryFormIsMan" type="text" name="isVIP"
                            data-toggle="topjui-combobox"
                            data-options="width:150,data:[{value:'',text:''},{value:'@L("是")',text:'@L("是")'},{value:'@L("否")',text:'@L("否")'}]" data-name="isMan" data-op="eq" data-datatype="tinyint">
                 </span>
                 <a href="javascript:void(0)" data-toggle="topjui-linkbutton" data-options="iconCls:'fa fa fa-search',btnCls:'topjui-btn-search'" onclick="searchQuery()">@L("搜索(enter)")</a>
                 <a href="javascript:void(0)" data-toggle="topjui-linkbutton" data-options="iconCls:'fa fa-mail-reply',btnCls:'topjui-btn-clear'" onclick="$('#myQueryForm').form('clear')">@L("清空(esc)")</a>
             </form>
        </div>
    </div>
</div>
 
<template id="TmpBatchUpdate" style="display:none">
    <label>@L("学生姓名")</label>
    <input value="" type="text" name="studentName" data-toggle="topjui-textarea" data-options="required: false,width:240,height:100">
    <label>@L("学生年龄")</label>
    <input value="" type="text" name="studentAge" data-toggle="topjui-textarea" data-options="required: false,width:240,height:100">
</template>

<!--自定义修改,尽量不要改框架的代码,修改全放这里,如果要修改框架代码,尽量在这里写个方法,在框架调用-->
<script>
    var demoStudent2Index={
        queryObj: $.dm.getQueryObj(), // URL的参数
        buInfo: $.dm.getBuInfo(), // 门店信息
        userInfo: $.dm.getUserInfo(), // 用户信息
        appInfo:$.dm.getAppInfo(), // 系统信息
        selfClick:function (){ // 自定义按钮对应的方法
            alert("123");
            // 选择一行
            $('#myDg').datagrid('selectRow', 1);
            // 提示信息
            //$.iMessager.alert('自定义方法', '自定义方法被执行了！', 'messager-info');

            //var checkedRows = $('#productDg').iDatagrid('getChecked');
            //console.log(checkedRows);

            //var options = $('#myDg').iDatagrid('options');
            //var selectedRow = $('#myDg').iDatagrid('getSelected');
            //console.log(selectedRow);

            // 提交参数查询表格数据
            //$('#productDg').iDatagrid('reload', {
            //    name: $('#name').iTextbox('getValue'),
            //    code: $('#code').iTextbox('getValue')
            //});
        }
    }
</script>

<!--全局变量和公共方法-->
<script>
    // 处理添加和编辑的时候load之后调用的方法
    function addOrEditLoad(type, uuid) {

        if (type == "add") {
        }

        if (type == "edit") {
        }
    }

    // 保存时用户的自定义验证
    function userValidate() {
        //var myFormProductGUIDValue = $("#myFormProductGUID").iCombobox("getValue");
        //if (myFormProductGUIDValue.length != 36) {
        //    layer.msg("@L("请选择对应产品")");
        //    return false;
        //}

        return true;
    }
    
    // 新增初始化form操作
    function formAddInit(formDialog) {
        var result = {
            studentName:'123'
        };
       // formDialog.form('load', result);

        //var options = {
        //    url: '/api/services/app/DemoStudent2/GetViewDto',
        //    maskJqSelect: '#myFormDialog'
        //};

        //var success = function (result) {
        //    $editDialog.form('load', result);
        //}

        //abp.ajax(options).done(success);
    }
</script>

<!--表格操作-->
<script>
    // 定义初始化过滤条件
    var myDgInitFilter = null;
    if (demoStudent2Index.queryObj.classGUID) {
        myDgInitFilter = {
        Type: "and",
        conditions: [{
            attribute: "classGUID",
            datatype: "uniqueidentifier",
            operatoer: "eq",
            value: demoStudent2Index.queryObj.classGUID
            
        }]
       };
    }

    // 获取过滤条件
    function getFilters() {
        var initFilter = null;
        var filter = $.ei.getFilters(); // 获取界面查询条件

        // 如果有初始化条件那么把初始化的条件加上去
        if (myDgInitFilter && myDgInitFilter.conditions) {
            initFilter =  _.cloneDeep(myDgInitFilter);
            if (filter) {
                initFilter.conditions = _.union(filter.conditions, myDgInitFilter.conditions);
            }
        } else if (filter) {
            initFilter = filter; // 没有初始化条件 那么用查询的条件
        }

        if (initFilter) {
            return JSON.stringify(initFilter);
            // return $.ei.dealMultipleFilter(initFilter); // 查询存在多选的的时候 用这个
        } else {
            return null;
        }
    }
    
    // 表格查询
    function searchQuery() {
        var param = $('#myDg').iDatagrid('options').queryParams;
        param.filter = getFilters();
        $('#myDg').iDatagrid('load', param);
    }

    $(function () {
        $("#mySearchForm").show();
        // 初始化表格
        var dg = $('#myDg').iDatagrid({
        url: '/api/services/app/DemoStudent2/GetGridDto',
        fitColumns: true,
        queryParams: {
            order: 'CreateTime  desc',
            viewName: 'view_Demo_Student2',
            filter: getFilters()
        },
        // 加载前数据重新请求 用于后端请求数据统计
        onBeforeLoad: function () {
            //var param = $(this).iDatagrid('options').queryParams;
            //var data = { gridInDto: param };
            //var options = {
            //    url: '/api/services/app/DemoStudent2/GetGridSummary',
            //    maskJqSelect: '#spnGridSummary',
            //    data: data
            //};

            //var success = function (result) {
            //    var gridSummarHtml = _.template("总年龄:<b><%= createdName %></b> &nbsp;Vip人数:<b><%= id %></b>")(result.data);
            //    $("#spnGridSummary").html(gridSummarHtml);
            //}

            //abp.ajax(options).done(success);
        },
        columns: [
            [
                {
                    field: 'id',
                    title: 'id',
                    checkbox: true,
                    datatype: 'uniqueidentifier',
                },

                {
                    field: 'classGUID',
                    title: '@L("班级GUID")',
                    hidden: true,
                    datatype: 'uniqueidentifier',
                },

                {
                    field: 'studentName',
                    title: '@L("名称")',
                    width: 120,
                    sortable: true,
                    datatype: 'nvarchar',
                },

                {
                    field: 'studentAge',
                    title: '@L("年龄")',
                    width: 80,
                    sortable: true,
                    datatype: 'int',
                },

                {
                    field: 'studentBirthday',
                    title: '@L("生日")',
                    width: 120,
                    sortable: true,
                    formatter: $.ei.dateFormatter,
                    datatype: 'datetime2',
                },

                {
                    field: 'studentGarde',
                    title: '@L("年级")',
                    width: 120,
                    sortable: true,
                    datatype: 'nvarchar',
                },

                {
                    field: 'studentHeight',
                    title: '@L("身高")',
                    width: 100,
                    sortable: true,
                    formatter: $.ei.moneyFormatter,
                    datatype: 'money',
                },

                {
                    field: 'studentIsVip',
                    title: '@L("是否VIP")',
                    width: 120,
                    sortable: true,
                    formatter: $.ei.boolFormatter,
                    datatype: 'tinyint',
                },

                
                {
                    field: 'isMan',
                    title: '@L("学生性别")',
                    width: 120,
                    sortable: true,
                    formatter: $.ei.boolFormatter,
                    datatype: 'tinyint',
                },

                {
                    field: 'studentLevel',
                    title: '@L("学生等级")',
                    width: 120,
                    sortable: true,
                    formatter: $.ei.colEnumFormatter('@L("学生等级(1,学霸;2,普通;3,学渣)")'),
                    datatype: 'int',
                },

                {
                    field: 'studentDesc',
                    title: '@L("学生描述")',
                    width: 120,
                    sortable: true,
                    datatype: 'nvarchar',
                },

                {
                    field: 'studentFavor',
                    title: '@L("学生爱好")',
                    width: 120,
                    sortable: true,
                    datatype: 'nvarchar',
                },

                {
                    field: 'studentStudentHeadUrl',
                    title: '@L("学生头像")',
                    width: 120,
                    sortable: true,
                    datatype: 'nvarchar',
                    formatter: $.ei.imgFormatter,
                },

                {
                    field: 'studentMeRemark',
                    title: '@L("学生自传")',
                    width: 120,
                    sortable: true,
                    datatype: 'nvarchar',
                },

                {
                    field: 'studentFile',
                    title: '@L("学生个人资料")',
                    width: 120,
                    sortable: true,
                    datatype: 'nvarchar',
                    formatter: $.ei.fileFormatter,
                },

                //{
                //    formatter: operateFormatter,
                //    field: '1 as  operate',
                //    title: '@L("操作")',
                //    sortable: true,
                //    width: 100
                //}
            ]
        ],
        onDblClickRow: function (a, b) {
            @if (currentUserInfo.IsHaveRights("Demo_Student2", "02") && base.Context.Request.Query["mode"]!="3" ){
            <text>
            openEditDiag(b.id);
            </text>}
            else{
            <text>
            openDetailDiag(b.id);
            </text>}
        },
        frozenColumns: [[

        ]],
        filter: [
            {
                field: 'studentName',
                type: 'textbox',
                op: ['contains', 'equal', 'notequal', 'endwith', 'beginwith']
            },

            {
                field: 'studentAge',
                type: 'numberbox',
                op: ['equal', 'notequal', 'less', 'lessorequal', 'greater', 'greaterorequal']
            },

            {
                field: 'studentBirthday',
                type: 'datebox',
                op: ['equal', 'notequal', 'less', 'lessorequal', 'greater', 'greaterorequal'],
                dataType: 'datetime'
            },

            {
                field: 'studentHeight',
                type: 'numberbox',
                op: ['equal', 'notequal', 'less', 'lessorequal', 'greater', 'greaterorequal'],
                options: {
                    precision: 2
                }
            },

            {
                field: 'studentGarde',
                type: 'textbox',
                op: ['contains', 'equal', 'notequal', 'endwith', 'beginwith']
            },

            {
                field: 'studentIsVip',
                type: 'combobox',
                options: {
                    valueField: 'value',
                    textField: 'text',
                    editable: false,
                    data: [{
                        text: '是',
                        value: '1'
                    }, {
                        text: '否',
                        value: '0'
                    }]
                },
                op: ['equal', 'notequal',]
            },

            {
                field: 'IsMan',
                type: 'combobox',
                options: {
                    valueField: 'value',
                    textField: 'text',
                    editable: false,
                    data: [{
                        text: '是',
                        value: '1'
                    }, {
                        text: '否',
                        value: '0'
                    }]
                },
                op: ['equal', 'notequal',]
            },

            {
                field: 'studentLevel',
                editable: false,
                type: 'combobox',
                op: ['equal', 'notequal'],
                dataType: 'int',
                options: {
                    valueField: 'value',
                    textField: 'text',
                    url: '/api/services/app/Enum/GetEnumArray',
                    queryParams: {
                        'enumTypeName': 'DemoStudent2StudentLevelEnum', 'module': 'Demo'
                    }
                }
            },

            {
                field: 'studentDesc',
                type: 'textbox',
                op: ['contains', 'equal', 'notequal', 'endwith', 'beginwith']
            },

            {
                field: 'studentFavor',
                type: 'textbox',
                op: ['contains', 'equal', 'notequal', 'endwith', 'beginwith']
            },

            {
                field: 'studentStudentHeadUrl',
                type: 'textbox',
                op: ['contains', 'equal', 'notequal', 'endwith', 'beginwith']
            },

            {
                field: 'studentMeRemark',
                type: 'textbox',
                op: ['contains', 'equal', 'notequal', 'endwith', 'beginwith']
            },

            {
                field: 'studentFile',
                type: 'textbox',
                op: ['contains', 'equal', 'notequal', 'endwith', 'beginwith']
            },

        ]
    });
 })

   function operateFormatter(value, row, index) {
       var htmlStr = '<button class="layui-btn layui-btn-xs" onclick="openDetailDiag(\'{0}\')">查看</button>'.format(row.id);
        @if (currentUserInfo.IsHaveRights("Demo_Student2", "02"))
        {
           <text>
             htmlStr += '<button class="layui-btn layui-btn-xs" onclick="openEditDiag(\'{0}\')">编辑</button>'.format(row.id);
           </text>
        }

        @if (currentUserInfo.IsHaveRights("Demo_Student2", "03"))
        {
            <text>
              htmlStr += '<button class="layui-btn layui-btn-xs layui-btn-danger" onclick="deleteRow(\'{0}\')">删除</button>'.format(row.id);
            </text>
        }

        return htmlStr;
    }
</script>

<!--按钮相关-->
<script>
function oepnAddDiag() {
        var $editDialog = $('<form id="myFormDialog"></form>'); // 创建form表单元素
        $editDialog.iDialog({
            title: '@L("新增学生表")',
            width: 750,
            height: 550,
            maximized: false, // 初始化是否最大化
            href: '/Demo/DemoStudent2/DemoStudent2Edit?mode=1',
                buttons: [{
                text: '@L("保存")',
                iconCls: 'fa fa-save',
                btnCls: 'topjui-btn-blue',
                handler: function () {
                    saveDate("saveAndClose");
                }
            },
            {
                text: '@L("保存&新增")',
                iconCls: 'fa fa-save',
                btnCls: 'topjui-btn-blue',
                handler: function () {
                    saveDate("saveAndNew");
                }
            }, 
            //{
            //    text: '@L("保存&关闭")',
            //    iconCls: 'fa fa-save',
            //    btnCls: 'topjui-btn-blue',
            //    handler: function () {
            //        saveDate("saveAndClose");
            //    }
            //},
            {
                text: '@L("关闭")',
                iconCls: 'fa fa-close',
                btnCls: 'topjui-btn-red',
                handler: function () {
                    $('#myFormDialog').iDialog('close');// 销毁dialog面
                }
            }],
            onLoad: function () {
                addOrEditLoad("add");
                formAddInit($editDialog);
            }
        });
    }

    function openEditDiag(uuid) {
        if (!uuid) {
            var selectedRow = $('#myDg').iDatagrid('getSelected');
            uuid = selectedRow.id;
        }
        var $editDialog = $('<form id="myFormDialog"></form>'); // 创建form表单元素
        $editDialog.iDialog({
            title: '@L("编辑学生表")',
            width: 750,
            height: 550,
            maximized: false, // 初始化是否最大化
            href: '/Demo/DemoStudent2/DemoStudent2Edit?uuid={0}&mode=2'.format(uuid),
            // modal: true,
            buttons: [
            @if (currentUserInfo.IsHaveRights("Demo_Student2", "02")) {
            <text>
            {
                text: '@L("保存")',
                iconCls: 'fa fa-save',
                btnCls: 'topjui-btn-blue',
                handler: function () {
                    saveDate("saveAndClose");
                }
            },
            </text>}
           {
                text: '@L("保存&新增")',
                iconCls: 'fa fa-save',
                btnCls: 'topjui-btn-save',
                handler: function () {
                    saveDate("saveAndNew");
                }
            }, 
            {
                text: '@L("关闭")',
                iconCls: 'fa fa-close',
                btnCls: 'topjui-btn-red',
                handler: function () {
                    $('#myFormDialog').iDialog('close');// 销毁dialog面
                }
            }],
            onLoad: function () {
                addOrEditLoad("edit",uuid);
                var data = { 'id': uuid };
                var options = {
                    url: '/api/services/app/DemoStudent2/GetViewDto',
                    maskJqSelect: '#myFormDialog',
                    data:data
                };

                var success = function (result) {
                    $editDialog.form('load', result);

                    // 绑定combox
                    $editDialog.find('[data-toggle="topjui-combobox"]').each(function (b) {
                        var c = $(this);
                        var opt = getOptionsJson(c);
                        if (opt.queryParams&&opt.queryParams.viewName) {
                            c.iCombobox(opt);
                        }
                    });

                    
                    // 在这里进行绑定UeEditor
                    $editDialog.find('[data-toggle="topjui-ueditor"]').each(function (b) {
                        var c = $(this);
                        var name = c.attr('name');
                        var opt = getOptionsJson(c);
                        var id = opt.id;
                        var ue = UE.getEditor(id);
                        ue.ready(function () {
                            ue.setContent(result[name]);
                        });
                    });
                    
                    @if (!currentUserInfo.IsHaveRights("Demo_Student2", "02")) {
                    <text>
                    $editDialog.form('readonly');
                    </text>}
                }

                abp.ajax(options).done(success);
            }
        });
    }

    // operate表示操作类型有 save saveAndClose saveAndNew
    function saveDate(operate) {
        // 1. 显示进度条（提交时请使用进度条 或者 禁用'提交'按钮，防止因为网络延迟用户重复提交）
        $.iMessager.progress({ 'text': '@L("保存中...")' });
        var isValid = $('#myFormDialog').iForm('validate'); //  提交数据表单数据时进行表单验证
        var isUserValid = userValidate();
        if (!isValid || !isUserValid) {
            layer.msg('@L("格式不正确,请填写对应的必填项!")');
            $.iMessager.progress('close');  // 如果表单是无效的则隐藏进度条
            return;
        }

        var data = $.dm.parseQueryString($('#myFormDialog').serialize());
        var options = {
            url: '/api/services/app/DemoStudent2/CreateByDto',
            data: data
        };

        // 有ID就是更新
        if (data.id) {
            options.url = '/api/services/app/DemoStudent2/UpdateByDto'
        }
        var success = function (result) {
            $("#myDg").iDatagrid('reload'); // 刷新下表格数据
            $('#myFormDialog').iForm('load', { id: result.id });
            // 保存并关闭
            if (operate === 'saveAndClose') {
                $.iMessager.show({ title: '@L("我的消息")', msg: '@L("保存成功")', timeout: 2000, showType: 'slide' });// '消息窗口'组件
                $('#myFormDialog').iDialog('close');// 销毁dialog面板
            } else if (operate === 'saveAndNew') {
                // 保存新增重置form
                $("#uuid").val(""); // 清空GUID
                // $('#myFormDialog').iForm('reset'); // 全部清空
                // $('#myFormDialog').iForm('load', { userGUID:''}); // 清空某些数据
                // UE.getEditor('myFormDayReportDesc').setContent('');
                formAddInit($('#myFormDialog'));
                layer.msg("@L("保存成功")");
            } else {
                layer.msg("@L("保存成功")");
            }
        }
        abp.ajax(options).done(success);
    }

    function openDetailDiag(uuid) {
         if (!uuid) {
            var selectedRow = $('#myDg').iDatagrid('getSelected');
            uuid = selectedRow.id;
        }
        var $editDialog = $('<form id="myDetailDialog"></form>'); // 创建form表单元素
        $editDialog.iDialog({
            title: '@L("查看学生表")',
            width: 750,
            height: 550,
            href: '/Demo/DemoStudent2/DemoStudent2Detail?uuid=' + uuid,
            buttons: [ {
                text: '@L("关闭")',
                iconCls: 'fa fa-close',
                btnCls: 'topjui-btn-red',
                handler: function () {
                    $('#myDetailDialog').dialog('close');// 销毁dialog面
                }
            }],
            onLoad: function () {
                var data = { 'id': uuid };
                var options = {
                    url: '/api/services/app/DemoStudent2/GetViewDto',
                    maskJqSelect: '#myDetailDialog',
                    data : data
                };

                var success = function (result) {
                        $("#DemoStudent2DetailTableTemplate").tmpl(result)
                        .appendTo("#DemoStudent2DetailTable");
                }
                abp.ajax(options).done(success);
            }
        });
    }


    // 删除行数据
    function deleteRow(id) {
        $.messager.confirm("@L("提示")", "@L("确定要删除该条数据吗?")", function (result) {
            if (result) {
                $.iMessager.progress({ 'text': '@L("处理中...")' });
                var data={'id':id};
                var options = {
                    url: '/api/services/app/DemoStudent2/DeleteByDto',
                    maskJqSelect: '#myDg',
                    data: data
                };

                var success = function (result) {
                    $("#myDg").iDatagrid('reload');// 刷新下表格数据
                    $.iMessager.show({ title: '@L("我的消息")', msg: '@L("删除成功")', timeout: 2000, showType: 'slide' });// '消息窗口'组件
                }

                abp.ajax(options).done(success);
            }
        })
    }

    // 删除验证
    function vaildateBatchDelete(selectRows) {
        var isValidate = true;
        //_.forEach(selectRows, function (item, index) {
            //if (item.studentName !== 'test') {
                //$.iMessager.alert("警告", "{0}行的不能删除,只能删除test用户".format(index+1));
                //isValidate = false;
                //return false;
            //}
        //});
        return isValidate;    }

    // 批量更新操作
    function batchUpdate() {
         var selectedRows = $('#myDg').iDatagrid('getChecked');
	    if (selectedRows.length == 0) {
		    $.iMessager.alert("提示", "请至少勾选一行");
		    return;
	    }
	    function validateRows(selectedRows){
		    return true;
	    }
	    if (validateRows(selectedRows)) {
		    var $editDialog = $('<form id="myFormDialog"> </form>'); // 创建form表单元素
		    $editDialog.iDialog({
			    title: '@L("提示框")',
			    width: 300,
			    height: 250,
                content: $("#TmpBatchUpdate").html(),
			    buttons: [{
				    text: '@L("保存")',
				    iconCls: 'fa fa-save',
				    btnCls: 'topjui-btn-save',
                    handler: function () {
                        var formData = $('#myFormDialog').serializeObject();
                        var batchDtos = [];

                        _(formData).forEach(function (value,key ) {
                            var dto = {
                                name: key,
                                value: value
                            };
                            batchDtos.push(dto);
                        })

					    var data = {
						    ids: _(selectedRows).map("id").value(),
                            batchDtos: batchDtos
					    };

					    $.iMessager.progress({ 'text': '@L("保存中...")' });
					
					    var options = {
                            url: '/api/services/app/DemoStudent2/BatchUpdateByDto',
						    data: data
					    };

					    var success = function (result) {
						    $("#myDg").iDatagrid('reload');// 刷新下表格数据
						    $.iMessager.show({ title: '@L("我的消息")', msg: '@L("保存成功")', timeout: 2000, showType: 'slide' });// '消息窗口'组件
						    $('#myFormDialog').iDialog('close');// 销毁dialog面板
					    }

					    abp.ajax(options).done(success);
                        
				    }
			    },
			    {
				    text: '@L("关闭")',
				    iconCls: 'fa fa-close',
				    btnCls: 'topjui-btn-close',
				    handler: function () {
					    $('#myFormDialog').iDialog('close');// 销毁dialog面
				    }
			    }]
		    });
	    }
    }
</script>

